﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BySoft.Server.Common.Entity;
using BySoft.Server.Business;
using BySoft.Web.Utility;
using System.Data;

namespace BySoft.Web.Site.MastePage
{
    public partial class Frame : System.Web.UI.MasterPage
    {
        public string ValidationGroup
        {
            set
            {
                Master.ValidationGroup = value;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {

            if (Session["Login_User"] != null)
            {
                SysUserEntity objUser = ((SysUserEntity)Session["Login_User"]);
                lblUser.Text = objUser.UserName;

                SetProxyMsg(objUser.UserID);
            }
            if (Session["Login_FactoryType"] != null)
            {
                string obstrLogin_FactoryTypejUser = ((string)Session["Login_FactoryType"]);
                switch (obstrLogin_FactoryTypejUser)
                {
                    case "1": lblFactoryType.Text = "苏州"; break;
                    case "2": lblFactoryType.Text = "东莞"; break;
                }
            }
            
        }

        private void SetProxyMsg(string strUserID)
        {
            string strIsProxy = ClsComm.GetProxy(strUserID);
            if (string.IsNullOrEmpty(strIsProxy))
            {
                lblIsProxy.Visible = false;
            }
            else
            {
                lblIsProxy.Visible = true;
                if (strIsProxy.Equals("1"))
                {
                    lblIsProxy.Text = "取消代理";
                }
                else
                {
                    lblIsProxy.Text = "代理审核";
                }
            }
        }


        //退出登录按钮
        protected void ibtnLogout_Click(object sender, EventArgs e)
        {
            Session["Login_User"] = null;
            Session["Login_FactoryType"] = null;
            Response.Redirect("Login.aspx");
        }

        protected void btnProxy_Click(object sender, EventArgs e)
        {
            SysUserEntity objUser = ((SysUserEntity)Session["Login_User"]);
            string strIsProxy = lblIsProxy.Text.Equals("代理审核") ? "1" : "0";
            if (strIsProxy.Equals("1"))
            {
            }
            else
            {
                btnSetProxy_Click(null, null);
            }
        }

        protected void btnSetProxy_Click(object sender, EventArgs e)
        {
            SysUserEntity objUser = ((SysUserEntity)Session["Login_User"]);
            string strIsProxy = lblIsProxy.Text.Equals("代理审核") ? "1" : "0";
            ClsComm.UpdateProxy(objUser.UserID, strIsProxy);
            SetProxyMsg(objUser.UserID);
            UIHelper.RunScript(this.Page, "reloadsys();");
        }
    }
}
